﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Technoera.Common.QueryModel
{
    public class SortUtilities
    {
        private SortUtilities() { }

        public static SortDirection Convert(System.Web.UI.WebControls.SortDirection sortDirection)
        {
            switch (sortDirection)
            {
                case System.Web.UI.WebControls.SortDirection.Ascending: return SortDirection.Ascending;
                case System.Web.UI.WebControls.SortDirection.Descending: return SortDirection.Descending;
                default: throw new NotSupportedException(sortDirection.ToString());
            }
        }

        public static SortInfo CreateSortInfoFromViewStateString(string sortParametersFromViewStateString, SortDirection sortDirection)
        {
            SortInfo sortInfo = new SortInfo();
            if (!string.IsNullOrEmpty(sortParametersFromViewStateString))
            {
                foreach (var sortExpression in sortParametersFromViewStateString.Split(new char[] { '|' }))
                {
                    sortInfo.Parameters.Add(new SortParameter(sortExpression, sortDirection));
                }
            }
            return sortInfo;
        }


    }
}
